import request from '@/utils/request'

export default class Employee {
  static getEmployeeListService = ({
    page,
    pagesize,
    keyword,
    departmentId
  }: any) =>
    request.get('/sys/user', {
      params: { page, pagesize, keyword, departmentId }
    })

  // 导出员工接口
  static exportEmployeeService = () =>
    request.get(
      '/sys/user/export',
      // config?: AxiosRequestConfig<D>改变接收数据类型
      // blob为二进制文件流，binary
      { responseType: 'blob' }
    )

  //下载员工导入模板
  static getExportTemplate = () =>
    request.get('/sys/user/import/template', { responseType: 'blob' })

  // 上传用户excel
  static uploadExcel = (data: any) => {
    request.post('/sys/user/import', data) // data为form-data类型
  }

  // 删除员工
  static deleteEmployeeService = (id: any) => request.delete(`/sys/user/${id}`)

  // 新增员工
  static addEmployeeService = (data: any) => request.post('/sys/user', data)

  // 获取员工详情，必须要路径参数
  static getEmployeeDetailService = (id: any) => request.get(`/sys/user/${id}`)

  // 更新员工
  static updateEmployeeService = (data: any) =>
    request.put(`/sys/user/${data.id}`, data)

  // 获取可用角色
  static getEnableRoleListService = () => request.get('/sys/role/list/enabled')

  // 分配员工角色
  static assignRoleService = (data: any) =>
    request.put(`/sys/user/assignRoles`, data)
}
